from selenium import webdriver
import time

driver = webdriver.Chrome()
driver.get('https://www.baidu.com')
driver.find_element_by_link_text('新闻').click()
time.sleep(2)
driver.find_element_by_link_text('地图').click()
time.sleep(2)
driver.find_element_by_link_text('贴吧').click()
time.sleep(2)
driver.find_element_by_link_text('图片').click()
time.sleep(2)
driver.find_element_by_link_text('网盘').click()
time.sleep(2)
print(driver.current_window_handle)
print(driver.window_handles)

driver.switch_to.window(driver.window_handles[2])

print(driver.current_window_handle)
print(driver.window_handles)

time.sleep(4)

driver.close()
driver.close()

time.sleep(2)
driver.quit()
